<?php
require_once 'conexao.php';
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <script type="text/javascript" src="ajax.js"></script>
        <script type="text/javascript" src="Funcoes.js"></script>
        <link rel="stylesheet" type="text/css" href="style.css"/>

        <script type="text/javascript"  language='javascript'>
            var txt=":: SISTEMA DE PORTARIA ::";
            var veloc=300;
            var refr=null;
            function rotulo_title(){
                document.title=txt;
                txt=txt.substring(1,txt.length)+txt.charAt(0);
                refr=setTimeout("rotulo_title()",veloc);
            }
            rotulo_title();
        </script>
        <script type="text/javascript"  language="JavaScript">
            // Copyright 2006-2007 javascript-array.com

            var timeout	= 80;
            var closetimer	= 0;
            var ddmenuitem	= 0;

            // open hidden layer
            function mopen(id)
            {
                // cancel close timer
                mcancelclosetime();

                // close old layer
                if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';

                // get new layer and show it
                ddmenuitem = document.getElementById(id);
                ddmenuitem.style.visibility = 'visible';

            }
            // close showed layer
            function mclose()
            {
                if(ddmenuitem) ddmenuitem.style.visibility = 'hidden';
            }

            // go close timer
            function mclosetime()
            {
                closetimer = window.setTimeout(mclose, timeout);
            }

            // cancel close timer
            function mcancelclosetime()
            {
                if(closetimer)
                {
                    window.clearTimeout(closetimer);
                    closetimer = null;
                }
            }

            // close layer when click-out
            document.onclick = mclose;
        </script>
    </head>
    <body onload="initTimer();" >
        <?php
        if (!isset($_SESSION['logado'])) {
            require_once 'login.php';
        } else {
        ?>

            <div id="superior">
                <div style="
                     position: absolute;
                     left: 1100px;
                     top: 70px;
                     ">
                    <a href="http://192.168.7.77/" target="_blank">
                        <img src="./imagens/cftv.jpg" width="70px" border="0"/>
                    </a>
                </div>

                <div>
                    <ul>
                        <ul id="menu_suspenso">
                            <li ><a href="index.php?pagina=grade" onmouseover="mopen('')" onmouseout="mclosetime()">Inicio</a>
                            </li>
                            <li><a href="#" onmouseover="mopen('sub1')" onmouseout="mclosetime()">Cadastro</a>
                                <div class="sub" id="sub1" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"/>
                                <a href="index.php?pagina=cadastro_visitante" id="cadastro_visitante" style="display: block">Visitantes</a>
                                <a href="index.php?pagina=cadastro_usuarios" id="cadastro_usuarios" style="display: block">Colaborador</a>
                                <a href="index.php?pagina=acesso_usuario" id="acesso_usuario" style="display: block">Acessos</a>
                                <a href="index.php?pagina=cadastro_mot" id="cadastro_mot" style="display: block">Motorista</a>
                                <a href="index.php?pagina=cadastro_veic" id="cadastro_veic" style="display: block">Veículo</a>
                                <a href="index.php?pagina=cadastro_operacao" id="cadastro_operacao" style="display: block">Operação</a>
                                <a href="index.php?pagina=cadastro_setor" id="cadastro_setor" style="display: block">Setor</a>
                            </li>
                            <li><a href="#" onmouseover="mopen('sub2')" onmouseout="mclosetime()">Movimentos</a>
                                <div class="sub" id="sub2" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"/>
                                <a href="index.php?pagina=visitantes" id="visitantes" style="display: block">Visitantes</a>
                                <a href="index.php?pagina=frota" id="frota" style="display: block">Frota</a>
                                <a href="index.php?pagina=prestador" id="prestador" style="display: block">Prestador</a>
                                <a href="index.php?pagina=agendamento" id="agendamento" style="display: block">Agendamento</a>
                            </li>
                            <li><a href="#" onmouseover="mopen('sub3')" onmouseout="mclosetime()">Relatórios</a>
                                <div class="sub" id="sub3" onmouseover="mcancelclosetime()" onmouseout="mclosetime()"/>
                                <a href="index.php?pagina=rel_visitante" id="rel_visitante" style="display: block">Visitante</a>
                                <a href="index.php?pagina=rel_frota" id="rel_frota" style="display: block">Frota</a>
                                <a href="index.php?pagina=rel_prestador" id="rel_prestador" style="display: block">Prestador</a>
                                <a href="index.php?pagina=rel_diarias" id="rel_diarias" style="display: block">Diárias</a>
                            </li>
                            <li><a href="index.php?pagina=logout" onmouseover="mopen('sub4')" onmouseout="mclosetime()">Logout</a></li>

                        </ul>
                    </ul>
                    <div style="
                         position: absolute;
                         left: 1085px;
                         top: -3px;
                         ">
                        <h4> <span id="timer"></span></h4>
                    </div>
                </div>

            </div>


        <?php
            echo "<div id='inferior'>";

            $validas = array('login', 'agendamento', 'visitantes', 'cadastro_usuarios','cadastro_visitante', 'rel_tempo_prestador', 'rel_tempo_ocioso', 'rel_prestador', 'rel_visitante', 'rel_frota', 'logout', 'cadastro_mot', 'frota', 'grade', 'prestador', 'cadastro_veic', 'acesso_usuario', 'cadastro_operacao', 'cadastro_setor', "rel_diarias");

            $sql_usuario = mysql_query("SELECT ID FROM usuario WHERE nome='" . $_SESSION['login'] . "'");
            $id_usuario = mysql_result($sql_usuario, 0, 0);

//--------------------------------------------INICIO DA VERIFICAÇÃO DOS ACESSOS (PÁGINAS E MENUS)
            $sql_acesso = mysql_query("select * from acesso where id = " . $id_usuario);
            $pagina_acesso = @mysql_result($sql_acesso, 0, 0);

            $sql_menu = mysql_query("select * from acesso where id = " . $id_usuario . " LIMIT 1");
            $vet_menu = mysql_fetch_array($sql_menu);

            $tamanho_tab = mysql_num_fields($sql_menu);

            for ($a = 1; $a <= $tamanho_tab; $a++) {
                $meta = @mysql_fetch_field($sql_menu, $a);
                if (@$vet_menu[$meta->name] == '0') {
                    echo"<script type='text/javascript'>
                            document.getElementById('$meta->name').style.display='none';
                        </script>";
                }
            }
//--------------------------------------------FIM DA VERIFICAÇÃO DOS ACESSOS (PÁGINAS E MENUS)
            if (!empty($_GET['pagina'])) {

                if (in_array($_GET['pagina'], $validas) && !is_null($vet_menu[$_GET['pagina']])) {
                    require_once( $_GET['pagina'] . ".php");
                }
            } else {
                require_once( "grade.php" );
            }
            echo "
            </div>
            <center>
            <div style='position: absolute; left: 550px; top: 610px'>
            <img src='http://www.saoexpedito.com.br/imagens/logo.jpg' style='margin-top: 100px; width: 150px'></img><br/><br/>
            <a style='font-size: 11px'>Copyright© Transportes São Expedito LTDA</a><br />
            <a style='font-size: 11px'>Departamento de TI - TSE</a>
            </div>
            </center >
            ";
        }
        ?>

    </body>
</html>
